package com.cxy.mapper;


import com.cxy.dto.RecordPageDTO;
import com.cxy.entity.Record;
import com.cxy.vo.AssessRecordVO;
import com.cxy.vo.ByAndStatusVO;
import com.cxy.vo.RecordVO;

import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface RecordMapper {
    /**
     * 批量查询评议记录
     * @param recordPageDTO
     * @return
     */
    Page<RecordVO> page(RecordPageDTO recordPageDTO);

    /**
     * 新增评议记录
     * @param record
     */
    @Insert("insert into record(user_id, task_id, byreviewuser_id) VALUES" +
            " (#{userId},#{taskId},#{byReviewUserId})")
    void insert(Record record);

    /**
     * 根据id查询当前用户的评议任务
     */
    List<ByAndStatusVO> seeAssess(Long userId, Long taskId);

    /**
     * 对被评议用户评分
     */
    @Update("update record set score=#{score},status=2 " +
            "where byreviewuser_id=#{byReviewUserId} and user_id=#{userId} and task_id=#{taskId}")
    void mark(Double score,Long byReviewUserId,Long userId,Long taskId);

    /**
     * 获取当前代评人数
     * @param userId
     * @param taskId
     * @return
     */
    @Select("select count(*) from record where user_id=#{userId} and task_id=#{taskId} and status=1")
    Long getNoNumber(Long userId, Long taskId);

    /**
     * 查询record表中的所有记录
     */
    @Select("select * from record where task_id=#{taskId}")
    List<Record>selectAll(Long taskId);

    /**
     * 查看当前任务的评议记录
     * @param dateNumber
     * @return
     */
    List<AssessRecordVO> seeAssessRecord(Long userId, String dateNumber);
}
